package cn.group.hotel2.controller;

import cn.group.hotel2.pojo.vo.OrderListItemVO;
import cn.group.hotel2.pojo.vo.OrderStandardVO;
import cn.group.hotel2.pojo.vo.RoomCheckInStandardVO;
import cn.group.hotel2.service.IOrderService;
import cn.group.hotel2.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 处理订单相关请求的控制器
 *
 * @author wcl
 * @version 0.0.1
 * @date 2022/11/22
 */
@Slf4j
@RestController
@RequestMapping("/orders")
@Api(tags = "05 订单管理模块")
public class OrderController {

    @Autowired
    private IOrderService orderService;

    public OrderController() {
        log.debug("创建控制器对象：OrderController");
    }

    @ApiOperation("根据订单号查询订单表数据详情")
    @ApiOperationSupport(order = 405)
    @GetMapping("/{orderNum}")
    @ApiImplicitParam(name = "orderNum", value = "订单号", required = true, dataType = "String")
    public JsonResult<OrderStandardVO> getStandardByOrderNum(@PathVariable String orderNum){
        log.debug("开始处理【根据订单号查询订单表数据详情】请求,参数:{}", orderNum);
        OrderStandardVO queryResult = orderService.getStandardByOrderNum(orderNum);
        return JsonResult.ok(queryResult);
    }

    @GetMapping("/list")
    public JsonResult<List<OrderListItemVO>> list(){
        return JsonResult.ok(orderService.list());
    }

    @GetMapping("/listPage/{currentPage}")
    public JsonResult<List<OrderListItemVO>> listPage(@PathVariable Integer currentPage){
        Integer current = (currentPage-1)*10;
        return JsonResult.ok(orderService.listPage(current));
    }

    @GetMapping("/count")
    public JsonResult<Integer> count(){
        return JsonResult.ok(orderService.count());
    }

    @GetMapping("/listByStatus/{status}")
    public JsonResult<List<OrderListItemVO>> listByStatus(@PathVariable Integer status){
        return JsonResult.ok(orderService.listByStatus(status));
    }

    @GetMapping("/countByStatus/{status}")
    public JsonResult<Integer> countByStatus(@PathVariable Integer status){
        return JsonResult.ok(orderService.countByStatus(status));
    }

    @PostMapping("/{id}/delete")
    public JsonResult<Void> deleteById(@PathVariable Long id){
        orderService.deleteById(id);
        return JsonResult.ok();
    }

}
